{extend name="./indexmb" /}

{block name="check_input"}

<div class="layui-inline">
    <div class="layui-input-block">
        <select name="post_class_id" lay-filter="type">
            <option value="">分类</option>
            {foreach $class as $k=>$v}
            <option value="{$v.id}">{$v.name}</option>
            {/foreach}
        </select>
    </div>
</div>
<div class="layui-inline">
    <div class="layui-input-inline"  style="width:350px;">
        <input type="text" name="create_time" class="layui-input" id="time_time" placeholder="开始时间至结束时间">
    </div>
</div>
<div class="layui-inline">
    <div class="layui-input-block">
        <input type="text" name="user_name" placeholder="发帖用户" autocomplete="off" class="layui-input">
    </div>
</div>
{/block}
{block name="setting_all_botton"}
{/block}
{block name="setting_botton"}
<button type="button" onclick="data_delete({{d.id}})" class="layui-btn  layui-btn-sm layui-bg-red delete">删除
</button>
<button type="button" onclick="data_upload({{d.id}})" class="layui-btn  layui-btn-sm upload">详情
</button>
{/block}
{block name="layui"}
<script>
    function data_delete(id) {
        //删除按钮操作
        layui.use('layer', function () {
            var $ = layui.$
                , table = layui.table
                , layer = layui.layer;
            layer.confirm('确定删除吗？', function (index) {

                //执行 Ajax 后重载
                $.ajax({
                    'url': "{:url('delete')}",
                    'method': 'POST',
                    'data': {id: id},
                    'success': function (res) {
                        if (res.code == 200) {
                            layer.msg('删除成功', {
                                time: 1500 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                table.reload('demo');
                            });
                        } else {
                            layer.msg(res.message);
                        }
                    }
                })
            });
        })
    }

    function data_upload(id) {
        //编辑按钮操作
        layui.use('layer', function () {
            var $ = layui.$
                , table = layui.table
                , layer = layui.layer;
                var index = layer.open({
                    type: 2
                    , title: '详情'
                    , content: 'upload.html' + '?id=' + id
                    , maxmin: true
                    , area: ["{$popup_size.width}", "{$popup_size.height}"]
                    , btn: ['返回']
                });
                layer.full(index);

        });
    }

    layui.config({
        base: '/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'useradmin', 'table', 'layer', 'laydate'], function () {

        var $ = layui.$
            , form = layui.form
            , table = layui.table
            , layer = layui.layer
            , laydate = layui.laydate
        laydate.render({
            elem: '#time_time'
            , type: 'datetime'
            , range: '到'
            , format: 'yyyy-M-d H:m:s'
        });
        //表格
        var web_table = "{$table}";
        web_table = JSON.parse(web_table.replace(/&quot;/g, '"'));
        "{if $cs_url}"
        var url = "{:url('datalist')}" + "{$cs_url}";
        "{else}"
        var url = "{:url('datalist')}";
        "{/if}"
        url = url.replace(/&amp;/g, '&');
        console.log(url, 111)
        table.render({
            elem: '#demo'
            , limit: 50
            , url: url//数据接口
            , page: true //开启分页
            , cols: [web_table]
        });
        //监听搜索
        form.on('submit(LAY-user-front-search)', function (data) {
            var field = data.field;

            //执行重载
            table.reload('demo', {
                where: field
            });
        });

        //事件
        var active = {
            batchdel: function () {
                //批量删除按钮操作
                var checkStatus = table.checkStatus('demo')
                    , checkData = checkStatus.data; //得到选中的数据

                if (checkData.length === 0) {
                    return layer.msg('请选择数据');
                }

                var prompt = layer.prompt({
                    formType: 1
                    , title: '敏感操作，请验证口令'
                }, function (value, index) {
                    if (value !== '123456') {
                        return layer.msg('口令错误');
                    }
                    layer.closeAll();
                    var id = '';
                    for (var i = 0; i < checkData.length; i++) {
                        id += checkData[i]['id'] + ','
                    }
                    layer.confirm('确定删除吗？', function (index) {

                        //执行 Ajax 后重载
                        $.ajax({
                            'url': "{:url('delete')}",
                            'method': 'POST',
                            'data': {id: id},
                            'success': function (res) {
                                if (res.code == 200) {
                                    layer.msg('删除成功', {
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    }, function () {
                                        table.reload('demo');
                                    });
                                } else {
                                    layer.msg(res.message);
                                }
                            }
                        })
                    });
                });
            }
            , add: function () {
                //新增按钮操作
                layer.open({
                    type: 2
                    , title: '添加'
                    , content: 'add.html'
                    , maxmin: true
                    , area: ["{$popup_size.width}", "{$popup_size.height}"]
                    , btn: ['确定1', '取消']
                    , yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                        var submitID = 'LAY-user-front-submit'
                        var submit = layero.find('iframe').contents().find('#' + submitID);
                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                'url': "{:url('add_ajax')}",
                                'method': 'POST',
                                'data': field,
                                'success': function (res) {
                                    if (res.code == 200) {
                                        layer.msg('添加成功', {
                                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                        }, function () {
                                            table.reload('demo');
                                        });
                                    } else {
                                        layer.msg(res.message);
                                    }
                                }
                            });
                            layer.close(index); //关闭弹层
                        });

                        submit.trigger('click');
                    }
                });
            }
        };
        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    function data_url(table = null) {
        console.log(table)
        //优化
        $.ajax({
            url: "{:url('optimize')}",
            data: {tables: table},
            success: function (res) {
                console.log(res);
            }
        })
    };

    //弹出查看图片
    function fdtop(img) {
        $("#mc").css({display: 'flex'});
        $("#mc").find('img').attr('src', img);
    }

    //关闭弹出层
    $("#mc").click(function () {
        $("#mc").hide();
    })
</script>
{/block}